package com.zbxx.container.websocket.entity;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.persistence.*;

/**
 * @author 万仁杰
 * @date 2019/05/20
 */
@Getter
@Setter
@ToString
@Entity
/**
 * 此注解会创建外键关联 然后使用left join
 *
 * 所有注解只能单独在get方法上或者属性上  否则不生效
 * JSON序列化的时候使用双向注解会产生死循环
 */
@NamedEntityGraph(name = "user.graph",attributeNodes = {
        @NamedAttributeNode("company")
})
public class User {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    @Column(length = 32)
    private String account;

    private String username;

    private String password;

    private Integer companyId;

    /**
     * 多对一应该是不能维护一方的数据 insert update false  外键需要关闭 不然每次都创建一个外键
     */
    @JoinColumn(name = "companyId",referencedColumnName = "id",
            insertable = false,updatable = false,foreignKey =@ForeignKey(ConstraintMode.NO_CONSTRAINT) )
    @ManyToOne(fetch = FetchType.EAGER)
    private Company company;

    private String headImg;

    private String signature;

}
